package edu.dhu.leetcode;

/**
 * @ Author ：snow
 * @ Date   ：Created in 2020-04-29
 * @ Description：
 * @ Modified By：
 * @ Version:
 */
public class RepeatSolution {
    public int  solution(int[] nums){
        int i = 0;
        while(i < nums.length){
            if(nums[i] == i){
                i ++;
                continue;
            }
            if(nums[i] == nums[nums[i]]) return nums[i];

            // 交换位置
            int temp = nums[i];
            nums[i] = nums[temp];
            nums[temp] = temp;

            i++;
        }

        return -1;
    }
}
